

#include <vector>
#include "Utils.h"
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\core\core.hpp>
#include <iostream>
#include "SimpleBlobsLib.h"

int RecortaCaracteres()//( int argc, char** argv )
{
	const std::string caracteres = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
	const int numImgs = 5;
	const std::string imagens [numImgs]= 
	{
		"C:\\Users\\William\\Dropbox\\trabalho\\CARACTERES\\CourierNew2.png",
		"C:\\Users\\William\\Dropbox\\trabalho\\CARACTERES\\TimesNewRoman2.png",
		"C:\\Users\\William\\Dropbox\\trabalho\\CARACTERES\\verdana2.png",
		"C:\\Users\\William\\Dropbox\\trabalho\\CARACTERES\\Arial2.png",
		"C:\\Users\\William\\Dropbox\\trabalho\\CARACTERES\\Tahoma2.png"
	};
	const std::string savePath = "C:\\Users\\William\\Dropbox\\trabalho\\CARACTERES\\separados\\";

	int total = 0;
	for (int i = 0 ; i < numImgs;i++)
	{
		cv::Mat im = cv::imread(imagens[i],0);

		Blobs::BlobList blobs;
		blobs.FindBlobs(im,0);

		blobs.MergeNearest(3,45,40,45);


		auto rects = blobs.GetBlobRects();

		std::sort(rects.begin(),rects.end(),[](const cv::Rect& r0,const cv::Rect& r1){return r0.x < r1.x;});

		for(size_t n = 0 ; n < rects.size();n++)
		{
			//
			cv::imwrite(savePath +caracteres[n] + "_" + std::to_string((long long)total)+".bmp",im(rects[n]));
			cv::rectangle(im,rects[n],cv::Scalar(127));
			total++;
		}

		cv::imshow("opencv",im);
		cv::waitKey();


		

	}

	return 1;
}